package com.tjsinfo.tjsoa.vote.action;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.tjsinfo.tjsoa.vote.bo.ITVoteConformationBO;
import com.tjsinfo.tjsoa.vote.bo.ITVoteEstimatedBO;
import com.tjsinfo.tjsoa.vote.vo.TVoteConformation;
import com.tjsinfo.tjsoa.vote.vo.TVoteEstimated;

public class validateAction extends Action {
	private ITVoteConformationBO conformationBo;
	private ITVoteEstimatedBO estimatedBo;
	public void setConformationBo(ITVoteConformationBO conformationBo) {
		this.conformationBo = conformationBo;
	}
	public void setEstimatedBo(ITVoteEstimatedBO estimatedBo) {
		this.estimatedBo = estimatedBo;
	}
	@SuppressWarnings("unchecked")
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		try {
			String headId = request.getParameter("headId");
			List<TVoteEstimated> estimatedLists = estimatedBo.find(headId);
			List<TVoteConformation> conformationRow = conformationBo.findRowStatus("rowNum", headId);
			List<TVoteConformation> conformationColumn = conformationBo.findRowStatus("columnNum", headId);
			List<TVoteConformation> conformationLists = conformationBo.findBy(headId);
			
			String str = "0";
			if(conformationRow.size()>0)str="1";
			if(conformationColumn.size()>0)str="2";
			if(conformationLists.size()==0)str="3";
			if(estimatedLists.size()==0)str="4";
			
			response.setContentType("text/html; charset=UTF-8"); 
			response.getWriter().print(str);
			
			return null;
		} catch (Exception e) {
			e.printStackTrace();
			return mapping.findForward("failed");
		}
	}
}
